package nio.filecopyoftransform;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * 使用transferFrom文件拷贝
 */
public class FileCopyOfTransform {
    public static void main(String[] args) throws Exception{
        FileInputStream fileInputStream = new FileInputStream("D:\\netty\\src\\nio\\filecopyoftransform\\image1.jpg");
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\netty\\src\\nio\\filecopyoftransform\\image2.jpg");

        FileChannel fileChannelSource = fileInputStream.getChannel();
        FileChannel fileChannelDest = fileOutputStream.getChannel();

        fileChannelDest.transferFrom(fileChannelSource,0,fileChannelSource.size());

        fileChannelDest.close();
        fileChannelSource.close();
        fileOutputStream.close();
        fileInputStream.close();

    }
}
